package com.weitu.threeSimultaneities.safe.controller;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.base.annotaion.SystemLog;
import com.weitu.base.controller.BaseController;
import com.weitu.threeSimultaneities.safe.service.SafeFSDService;
import com.weitu.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

import static com.weitu.util.AjaxResult.fail;
import static com.weitu.util.AjaxResult.success;

/**
 * Created by WT on 2017/4/26.
 */
@Controller
@RequestMapping(value = "threeSimultaneities/safe/safeFSD")
public class SafeFSDController extends BaseController{
    @Autowired
    private SafeFSDService safeFSDService;

    /**
     * 添加项目可研阶段信息
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Transactional(readOnly = false)
    @SystemLog(module = "安全三同时", methods = "添加安全专业可研信息")
    public AjaxResult insertSelective() {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        getAddBasicFieldMap(paramMap);
        paramMap.put("delState", 0);
        int boo = safeFSDService.insertSelective(paramMap);
        boolean accFlag = AccessoryUtil.saveAccerssoryInfo(paramMap.get("subjectId").toString());
        if (boo >0&& accFlag) {
            return success("添加成功");
        } else {
            return fail("添加失败");
        }
    }

    /**
     * 编辑可研阶段信息
     * @return
     * @throws Exception
     */
    @ResponseBody
    @Transactional(readOnly = false)
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @SystemLog(module = "安全三同时", methods = "编辑安全专业可研信息")
    public AjaxResult editAjax() throws Exception {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        getEditBasicFieldMap(paramMap);
        int boo =safeFSDService.updateByPrimaryKeySelective(paramMap);
        boolean accFlag = AccessoryUtil.saveAccerssoryInfo(paramMap.get("subjectId").toString());
        if (boo == 1&& accFlag ) {
            return success("更新成功！");
        } else {
            return fail("更新失败！");
        }
    }
}
